Dart BigInt operator |
Syntax & Examples


BigInt.operator | operator

The `operator |` in Dart performs a bitwise OR operation between two BigInt objects.


Syntax of BigInt.operator |

The syntax of BigInt.operator | operator is:

operator |(BigInt other) → BigInt

This operator | operator of BigInt bit-wise or operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe BigInt object to perform the bitwise OR operation with


✐ Examples

1 Perform bit-wise OR operation

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with different values.
  2. We use the | operator to perform a bit-wise OR operation between num1 and num2.
  3. We print the result of the operation to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(10);
  BigInt num2 = BigInt.from(7);
  BigInt result = num1 | num2;
  print('Bit-wise OR of num1 and num2: $result');
}

Output

Bit-wise OR of num1 and num2: 15

2 Perform bit-wise OR operation with hexadecimal numbers

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with hexadecimal values.
  2. We use the | operator to perform a bit-wise OR operation between num1 and num2.
  3. We print the result of the operation to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(0x55);
  BigInt num2 = BigInt.from(0xAA);
  BigInt result = num1 | num2;
  print('Bit-wise OR of num1 and num2: $result');
}

Output

Bit-wise OR of num1 and num2: 255

3 Perform bit-wise OR operation with binary numbers

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with binary values.
  2. We use the | operator to perform a bit-wise OR operation between num1 and num2.
  3. We print the result of the operation to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(0b1100);
  BigInt num2 = BigInt.from(0b1010);
  BigInt result = num1 | num2;
  print('Bit-wise OR of num1 and num2: $result');
}

Output

Bit-wise OR of num1 and num2: 14

Summary

In this Dart tutorial, we learned about operator | operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.